package com.woniuxy.goods.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.request.ResponseResult;
import com.woniuxy.goods.entity.Goods;
import com.woniuxy.goods.service.GoodsService;
import com.woniuxy.goods.vo.BuyGoodsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsSerice;
    @GetMapping("/findAll")
    public ResponseResult<PageInfo<Goods>> findAll(Integer currentPage, Integer pageSize, String name){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.findAll(currentPage,pageSize,name));
    }

    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody Goods goods){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.add(goods));
    }

    @PutMapping("/edit")
    public ResponseResult<Boolean> edit(@RequestBody Goods goods){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.edit(goods));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id")Integer id){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.delete(id));
    }

    @PostMapping("/buyGoods")
    public ResponseResult<Boolean> buyGoods(@RequestBody BuyGoodsVo buyGoodsVo){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.buy(buyGoodsVo));
    }

    // 商品兑换记录表
    @GetMapping("/all")
    public ResponseResult<PageInfo<BuyGoodsVo>> all(Integer currentPage, Integer pageSize, String name){
        return new ResponseResult<>(ResponseResult.OK,goodsSerice.all(currentPage,pageSize,name));
    }

    @PutMapping("/editState/{id}")
    public ResponseResult<Boolean> editState(@PathVariable("id")Integer id){
       return new ResponseResult<>(ResponseResult.OK,goodsSerice.editState(id));
    }
}
